package com.example.system.controller;

import com.example.common.core.controller.BaseController;
import com.example.common.core.domain.R;
import com.example.common.core.domain.TableDataInfo;
import com.example.system.domain.announcement.dto.AnnouncementQueryDTO;
import com.example.system.domain.announcement.dto.AnnouncementSaveDTO;
import com.example.system.domain.announcement.vo.AnnouncementDetailVO;
import com.example.system.service.IAnnouncementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/announcement")
public class AnnouncementController extends BaseController {

    @Autowired
    private IAnnouncementService announcementService;

    @GetMapping("/list")
    public TableDataInfo list(AnnouncementQueryDTO announcementQueryDTO) {
        return announcementService.list(announcementQueryDTO);
    }

    //  /announcement/add
    @PostMapping("/add")
    public R<Void> add(@RequestBody AnnouncementSaveDTO announcementAddDTO) {
        return toR(announcementService.add(announcementAddDTO));
    }

    //  /announcement/detail
    @GetMapping("/detail")
    public R<AnnouncementDetailVO> detail(Long announcementId) {
        return R.ok(announcementService.detail(announcementId));
    }

    //  /announcement/edit
    @PutMapping("/edit")
    public R<Void> edit(@RequestBody AnnouncementSaveDTO announcementEditDTO) {
        return toR(announcementService.edit(announcementEditDTO));
    }

    //  /announcement/delete
    @DeleteMapping("/delete")
    public R<Void> delete(Long announcementId) {
        return toR(announcementService.delete(announcementId));
    }
    
    /**
     * 发布公告
     */
    @PutMapping("/publish")
    public R<Void> publish(Long announcementId) {
        return toR(announcementService.publish(announcementId));
    }
    
    /**
     * 下架公告
     */
    @PutMapping("/unpublish")
    public R<Void> unpublish(Long announcementId) {
        return toR(announcementService.unpublish(announcementId));
    }
}
